package com.xingshang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xingshang.model.po.Admin;
import com.xingshang.service.AdminService;
import com.xingshang.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
* @author 87547
* @description 针对表【wn_manager】的数据库操作Service实现
* @createDate 2025-04-14 09:09:37
*/
@Service("adminServiceImpl")
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin>
    implements AdminService{
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin login(String account, String password) {
        Admin admin = adminMapper.getUserByAccount(account);
        if(admin != null && admin.getPassword().equals(DigestUtils.md5DigestAsHex(password.getBytes()))) {
            return admin;
        }
        return null;
    }
    @Override
    public Admin findByAccountAndNotId(String account, Integer excludeId) {
        return this.lambdaQuery()
                .eq(Admin::getAccount, account)
                .ne(Admin::getId, excludeId)
                .one();
    }
    @Override
    public Admin findByAccount(String account) {
        QueryWrapper<Admin> wrapper = new QueryWrapper<>();
        wrapper.eq("account", account);
        return adminMapper.selectOne(wrapper);
    }
    @Override
    public Admin getUserByAccount(String account) {
        return lambdaQuery().eq(Admin::getAccount, account).one();
    }
}




